package com.sdcqjy.mylibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/3/31.
 * 用于继承的父Adapter 超adapter
 */
public abstract class SuperAdapter<T> extends BaseAdapter {
    public SuperAdapter(Context context, List<T> modeList) {
        this.context = context;
        this.modeList = modeList;
        inflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return modeList.size();
    }

    public Object getItem(int position) {
        return modeList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public abstract int getLayoutId();

    public abstract SuperViewHolder<T> getSuperAdapter(View convertView);

    protected List<T> modeList;
    protected Context context;
    protected LayoutInflater inflater;

    public View getView(int position, View convertView, ViewGroup parent) {
        SuperViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(getLayoutId(), null);
            holder = getSuperAdapter(convertView);
            convertView.setTag(holder);
        } else holder = (SuperViewHolder) convertView.getTag();
        holder.setData(modeList.get(position));
        return convertView;
    }

    public static class SuperViewHolder<T> {
        public SuperViewHolder(View view) {
        }

        public SuperViewHolder() {
        }

        protected T mode;

        public void setData(T mode) {
            this.mode = mode;
        }
    }
}
